<template>
	<!--新增对话框-->
	<el-dialog
		:title="editForm.id ? '编辑' : '新增'"
		:visible.sync="dialogVisible"
		width="600px"
		:before-close="handleClose"
	>
		<el-form :model="editForm" :rules="editFormRules" ref="editForm">
			<el-form-item label="报告日期" prop="reportDate" label-width="100px">
				<ReportDatePicker v-model="editForm.reportDate" />
			</el-form-item>
			<!-- <el-form-item label="类型ID" prop="typeId" label-width="100px">
				<TypeIdSelect v-model="editForm.typeId" :reportDate="editForm.reportDate" type="1" />
			</el-form-item> -->
			<!-- <el-form-item label="名称ID" prop="nameId" label-width="100px">
				<NameIdSelect v-model="editForm.nameId" :reportDate="editForm.reportDate" type="1" />
			</el-form-item> -->

            <el-form-item label="名称" prop="name" label-width="100px">
				<el-input v-model="editForm.name" autocomplete="off"></el-input>
			</el-form-item>
            <!-- <el-form-item label="类型" prop="type" label-width="100px">
				<el-input v-model="editForm.type" autocomplete="off"></el-input>
			</el-form-item> -->
            <el-form-item label="数量" prop="amount" label-width="100px">
				<el-input v-model="editForm.amount" autocomplete="off"></el-input>
			</el-form-item>
			
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="resetForm('editForm')">取 消</el-button>
			<el-button type="primary" @click="submitForm('editForm')">确 定</el-button>
		</div>
	</el-dialog>
</template>

<script>
import {formatServerDate} from '@/utils/date';
import ReportDatePicker from '@/components/reportDatePicker/Index.vue';
import TypeIdSelect from '@/components/typeIdSelect/Index.vue';
import NameIdSelect from '@/components/nameIdSelect/Index.vue';
import { isNumber } from '@/utils/validate';
import qs from 'qs';
import { error } from 'jquery';
export default {
	name: 'AddUpdateRevenue4',
	components: {
		ReportDatePicker,
		TypeIdSelect,
		NameIdSelect,
	},
	props: {
		type: {
			type: String,
			default: '4',
		}
	},
	data() {
		return {
			editForm: {},
			loading: false,
			dialogVisible: false,
			editFormRules: {
				name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
				reportDate: [{ required: true, message: '请选择报告日期', trigger: 'blur' }],
                type: [{ required: true, message: '请输入类型', trigger: 'blur' }],
                amount: [{ required: true, message: '请输入数量', trigger: 'blur' }],
				// percentNum: [{ required: true, message: '请输入百分比', trigger: 'blur' }],
			},
		};
	},
	mounted() {
		// this.getFarmList('');
	},

	methods: {
		resetForm(formName) {
			this.$refs[formName].resetFields();
			this.dialogVisible = false;
			this.editForm = {};
		},
		handleClose() {
			this.resetForm('editForm');
		},
		submitForm(formName) {
			this.$refs[formName].validate((valid) => {
				if (valid) {

                    const { reportDate, ...rest} = this.editForm;
					rest.reportDate = this.editForm.reportDate.toString();
                    
                    // let percent = percentNum;
					this.$axios
                    .post('/admin/boat/profit/export/' + (this.editForm.id ? 'edit' : 'edit')+'?' + qs.stringify(rest))
						// .post('/admin/boat/profit/export/' + (this.editForm.id ? 'edit' : 'edit'), 
                        //     {
                        //         params: {
                        //         // percentNum: percent,
                        //         //id:this.editForm.id,
                        //         // report_date: formatServerDate(reportDate, 'YYYY.MM'),
                        //         // operator:"1",
                        //         ...rest,
                        //     },
                        // })
						.then((res) => {
							this.$message({
								showClose: true,
								message: '恭喜你，操作成功',
								type: 'success',
								onClose: () => {
									this.$emit('refreshDataList');
								},
							});
							this.dialogVisible = false;
							this.resetForm(formName);
						});
				} else {
                    console.log('error submit!!');
                    
					return false;
				}
			});
		},
		checkIsDisabledDate(date){
			console.log(date);
			return true;
		},
		init(id) {
			this.dialogVisible = true;
			if (id != null && id != '' && id > 0) {
				this.$axios.get('/admin/boat/profit/export/detail?id=' + id).then((res) => {
                    const {result = {}} = res;
                    const {...rest} = result;

                    console.log("lxx");
					console.log(result.report_date);

                    this.editForm = {
                        id: id,
						amount: rest.amount,
                        name: rest.name,
                        // nameId: rest.name_id,
                        //reportDate: result.report_date ? formatServerDate(result.report_date) : '',
						reportDate: result.report_date,
                        // remark: rest.remark,
                        type: rest.type,
                    };
				});
			}
		},
	},
};
</script>

<style scoped>
.avatar-uploader .el-upload {
	border: 1px dashed #d9d9d9;
	border-radius: 6px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
}
.avatar-uploader .el-upload:hover {
	border-color: #409eff;
}
.avatar-uploader-icon {
	font-size: 28px;
	color: #8c939d;
	width: 178px;
	height: 178px;
	line-height: 178px;
	text-align: center;
}
.avatar {
	width: 178px;
	height: 178px;
	display: block;
}
</style>
